/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tletlis.model;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

/**
 * The Green brick shaped like a reversed L.
 * @author David
 */
public class BlueBrick extends AbstractBrick {


    //Enumeration for keeping track of rotation state
    enum State{UP,LEFT,DOWN,RIGHT};

    private State state;
  /**
   * Constructor for the Blue brick initializing the shape of the brick
   * and the starting state.
   * @param y The vertical position were the brick will start.
   * @param x The horizontal position were the brick will start.
   */
    public BlueBrick(int y, int x) {
            state = State.DOWN;
            cords = new ArrayList<Position>();
            distance = Position.getLength();
            cords.add(new Position(y,x));
            cords.add(new Position(y,x+distance));
            cords.add(new Position(y,x+(2*distance)));
            cords.add(new Position(y+distance,x+(2*distance)));
            color = Color.BLUE;
        }

     /**
    * Method returning the rotated shape of the brick.
    * @return List<Position>
    */
    
    @Override
    protected List<Position> rotateBrick() {
        List<Position> temp = new ArrayList<Position>();
        for(Position p: cords) {
            temp.add(new Position(p.getY(),p.getX()));
        }
        if(state == State.DOWN) {
            temp.set(0, new Position(cords.get(1).getY()-distance,cords.get(1).getX()));
            temp.set(1, new Position(cords.get(1).getY(),cords.get(1).getX()));
            temp.set(2, new Position(cords.get(0).getY()+distance,cords.get(0).getX()));
            temp.set(3, new Position(cords.get(1).getY()+distance,cords.get(1).getX()));

        }
        else if(state == State.LEFT) {
            temp.set(0, new Position(cords.get(1).getY()-distance,cords.get(1).getX()-distance));
            temp.set(1, new Position(cords.get(1).getY(),cords.get(1).getX()-distance));
            temp.set(2, new Position(cords.get(1).getY(),cords.get(1).getX()));
            temp.set(3, new Position(cords.get(1).getY(),cords.get(1).getX()+distance));

        }
        else if(state == State.UP) {
            temp.set(0, new Position(cords.get(2).getY()-distance,cords.get(2).getX()));
            temp.set(1, new Position(cords.get(2).getY()-distance,cords.get(2).getX()+distance));
            temp.set(2, new Position(cords.get(2).getY(),cords.get(2).getX()));
            temp.set(3, new Position(cords.get(2).getY()+distance,cords.get(2).getX()));

        }
        else if(state == State.RIGHT) {
            temp.set(0, new Position(cords.get(2).getY(),cords.get(2).getX()-distance));
            temp.set(1, new Position(cords.get(2).getY(),cords.get(2).getX()));
            temp.set(2, new Position(cords.get(2).getY(),cords.get(2).getX()+distance));
            temp.set(3, new Position(cords.get(3).getY(),cords.get(3).getX()+distance));

        }
        return temp;
    }
    @Override
    protected void nextState() {
        if(state == State.DOWN)
            state = State.LEFT;
        else if(state == State.LEFT)
            state = State.UP;
        else if(state == State.UP)
            state = State.RIGHT;
        else if(state == State.RIGHT)
            state = State.DOWN;

    }
}